package cn.tedu.service.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import cn.tedu.dao.NewsDao;
import cn.tedu.entity.News;
import cn.tedu.service.NewsService;
import cn.tedu.utils.DBUtil;

public class NewsServiceImpl implements NewsService {
	
	NewsDao ndao = new NewsDao();
	public List<News> getNewsList() {
		return ndao.getNewsList();
	}

	public List<News> getNewsById(Integer id) {
		return ndao.getNewsById(id);
	}

	public List<News> getNewsByName(String keyword) {
		return null;
	}

	public void insertNews(News news) {
		// TODO Auto-generated method stub
		
	}

	
	/*
	 * (non-Javadoc)
	 * @see cn.tedu.service.NewsService#getNewsById(java.lang.Integer)
	 
	public List<News> getNewsById(Integer id) {
		Connection conn = DBUtil.getConnection();
		List<News> newsList = new ArrayList<News>();
		try {
			String sql = "select * from news where news_id=? order by id desc limit 0,1";
			PreparedStatement ps =  conn.prepareStatement(sql);
			ps.setInt(1, id);
			ResultSet rs = ps.executeQuery();
			while(rs.next()){
				News news = new News();
				news.setId(rs.getInt("id"));
				news.setTitle(rs.getString("title"));
				news.setPubTime(rs.getDate("pub_time"));
				news.setAuthor(rs.getString("author"));
				news.setImgURL(rs.getString("img_url"));
				news.setNewsId(rs.getInt("news_id"));
				news.setContent(rs.getString("content"));
				news.setAmountOfReading(rs.getInt("amount_of_reading"));
				news.setAmountOfShare(rs.getInt("amount_of_share"));
				newsList.add(news);
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return newsList;
	}

	
	 * (non-Javadoc)
	 * @see cn.tedu.service.NewsService#getNewsByName(java.lang.String)
	 
	public List<News> getNewsByName(String type) {
		
		return null;
	}

	
	 * (non-Javadoc)
	 * @see cn.tedu.service.NewsService#getNewsList()
	 
	public List<News> getNewsList() {
		return null;
	}

	
	 * (non-Javadoc)
	 * @see cn.tedu.service.NewsService#insertNews(cn.tedu.entity.News)
	 
	public void insertNews(News news) {
		String sql = "INSERT INTO news (id, title, author, pub_time, content, news_type, amount_of_reading, amount_of_share, img_url) values(?,?,?,?,?,?,?,?,?)";
		
		
	}*/

}
